package tech.deepmind.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import tech.deepmind.entity.Role;

@Repository
public class RoleDaoImpl implements RoleDao{
	
	@Autowired
	private BaseDao baseDao;
	
	@Override
	public List<Role> getRoleList() {
		ResultSet rs = null;
		List<Role> roleList = new ArrayList<Role>();
		
		String sql = "select * from smbms_role";
		Object[] params = {};
		baseDao.dopstmt(sql, params);
		try {
			rs = baseDao.getResultSet();
			while(rs.next()){
				Role _role = new Role();
				_role.setId(rs.getInt("id"));
				_role.setRoleCode(rs.getString("roleCode"));
				_role.setRoleName(rs.getString("roleName"));
				roleList.add(_role);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			baseDao.closeAll(rs);
		}
		return roleList;
	}

}
